package com.yuma.rag.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class RagConfig {
    @Bean
    public ChatClient chatClient(ChatClient.Builder builder){
        return builder
                // AI预设角色
                .defaultSystem("你将作为一名java开发语言的专家，对于用户使用需求做出解答")
                .build();
    }

    @Bean  // 生成一个向量库
    public VectorStore vectorStore(EmbeddingModel embeddingModel){
        //1.创建向量库
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(embeddingModel)
                .build();
        //2.读取要定制的内容（从文件中读取)
        List<Document> documents = List.of(
                new Document("产品说明：名称：JAVA开发语言\n" +
                        "产品描述：Java是一种面向对象的开发语言。\n" +
                        "特性：\n" +
                        "1.封装\n" +
                        "2.继承\n" +
                        "3.多态\n"
                )
        );
        // 3.给向量库喂数据 (自定义知识库)
        simpleVectorStore.add(documents);
        return simpleVectorStore;
    }
}
